﻿using System.Collections.Generic;
using UnityEngine;

namespace CWM.Skinn
{
    public static partial class SkinnContextCommands
    {
        [CtxMenuItem("SkinnedMeshRenderer/Shapes/Edit Names",
            "Opens a wizard that creates and uses TextAssets to filter and rename blend-shapes." , 0)]
        public static void SkinnedMeshRendererShowShapeWizard()
        {
            List<Mesh> meshes = new List<Mesh>();
            foreach (var item in SkinnContext.GetContextItems())
            {
                var context = item.GetComponent<Renderer>();
                if (SkinnEx.IsNullOrNotInAScene(context)) continue;
                meshes.Add(context.GetSharedMesh());
            }

            SkinnBlendshapeWizard.ShowWizard(meshes.ToArray().GetBlendshapeNames().ToArray());
            SkinnContext.Finished();
        }
    }

    public static partial class SkinnContextCommands
    {
        [CtxMenuItem("SkinnedMeshRenderer/Shapes/Load",
            "Opens a wizard that loads renders as blend-shapes", 0)]
        public static void SkinnedMeshRendererShowShapeLoaderWizard()
        {
            var context = SkinnContext.GetContextItem().GetComponent<SkinnedMeshRenderer>();
            if (!SkinnEx.IsNullOrNotInAScene(context))
            {
                SkinnShapeLoaderWizard.ShowWizard(context);
            }
            SkinnContext.Finished();
        }
    }
}